home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume91
/
midi
/
casio
/
part01
/
hilo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-28
|
2KB
|
81 lines
/* hilo - print highest and lowest sample values */
#include <stdio.h>
short buffer[512];
main(argc,argv)
int argc;
char *argv[];
{
FILE *fopen(), *fp;
short sample, i, average;
short blockhisample, blocklosample;
short grandhisample = -32768, grandlosample = 32767;
long grandtotal = 0, nsamples = 0;
long blocktotal;
unsigned long blockvariance, grandvariance = 0;
unsigned long sample_squared;
if (argc != 2)
{
fprintf(stderr,"usage: hilo casiodumpfilename\n");
printf("argc %d\n",argc);
exit(1);
}
if ((fp = fopen(argv[1],"r")) == NULL)
{
perror(argv[1]);
exit(2);
}
if (fseek(fp,1024L,1) == -1)
{
perror(argv[1]);
exit(3);
}
while (fread(buffer,1024,1,fp) != 0)
{
nsamples += 512;
blockhisample = -32768;
blocklosample = 32767;
blocktotal = 0;
blockvariance = 0;
for (i = 0; i < 512; i++)
{
sample = buffer[i];
/* printf("%4x ",(sample >> 4) & 0xf); */
/* compute block values */
blocktotal += sample;
if (sample < blocklosample)
blocklosample = sample;
if (sample > blockhisample)
blockhisample = sample;
/* compute grand values */
grandtotal += sample;
if (sample < grandlosample)
grandlosample = sample;
if (sample > grandhisample)
grandhisample = sample;
/* compute variance */
sample_squared = ((sample / 32) * (sample / 32));
blockvariance += sample_squared;
grandvariance += sample_squared;
}
average = blocktotal/512;
printf("512 samples: avg %d, hi %d, lo %d, variance %ld\n",average,blockhisample,blocklosample,blockvariance * 2);
}
average = grandtotal/nsamples;
printf("totals: nsamples %ld, avg %d, hi %d, lo %d, variance %ld\n",nsamples,average,grandhisample,grandlosample,grandvariance * 2);
exit(0);
}